import { Button } from 'antd'
import type { ButtonType } from 'antd/lib/button'


const ActionBuilder = (
  actions: BasicListApi.Action[] | undefined,
  actionHandler: BasicListApi.ActionHandler,
  loading = false,
  record = {}
  ) => {
  return (actions || []).map(action => {
    if(action.component = 'button'){
      return <Button
                key={action.text}
                danger={action.text === 'Delete' ? true: false}
                type={action.text === 'Delete'? 'primary' :action?.type as ButtonType}
                onClick={() => { actionHandler(action, record) }}
                loading={loading}
             >

               {action?.text}

             </Button>
    }
    return null
  })
}

export default ActionBuilder
